﻿using UnityEngine;

namespace AudioStudio
{
    public abstract class AudioEventHandler : AudioGameObject
    {
        private bool started = false;
        private bool disabled = false;

        void Start()
        {
            HandleEnableEvent();
            started = true;
            disabled = false;
        }

        void OnEnable()
        {
            UpdatePosition();
            if (started)
            {
                HandleEnableEvent();
                disabled = false;
            }
        }

        void OnDisable()
        {
            if (started && !disabled)
            {
                HandleDisableEvent();
                disabled = true;
            }
        }

        new void OnDestroy()
        {
            if (started && !disabled)
            {
                HandleDisableEvent();
                disabled = true;
            }
            base.OnDestroy();
        }

        public abstract void HandleEnableEvent();
        public abstract void HandleDisableEvent();
    }
}